#pragma once

#include "TravianAutoTask.h"

// CViewTaskList view

class CViewTaskList : public CListView
{
	DECLARE_DYNCREATE(CViewTaskList)

protected:
	CViewTaskList();           // protected constructor used by dynamic creation
	virtual ~CViewTaskList();

public:
#ifdef _DEBUG
	virtual void AssertValid() const;
#ifndef _WIN32_WCE
	virtual void Dump(CDumpContext& dc) const;
#endif
#endif

protected:
	DECLARE_MESSAGE_MAP()

public:
	void	ClearTasks() { 	if (m_pts) { CTravianTask::ClearTasks(*m_pts); delete m_pts; m_vecTasksInfo.clear(); m_vecToolTipID.clear();} };
	void	SetTasks(Tasks* pts);
	Tasks*	GetTasks() { return m_pts;}
	void	SetTaskState(int nIndex, CTravianTask *ptask);

	int		GetImgIndex(eTaskExecState eState) {
		if (eState == E_EXEC_STATE_INITIAL) return 0;
		if (eState == E_EXEC_STATE_FINISHED) return 1;
		if (eState == E_EXEC_STATE_STOPPED) return 2;
		if (eState == E_EXEC_STATE_DELAYED) return 3;
		if (eState == E_EXEC_STATE_REFRESH) return 4;
		if (eState == E_EXEC_STATE_ACTION) return 3;
		return 0;
	};
	LPCTSTR	GetStateText(eTaskExecState eState) {
		if (eState == E_EXEC_STATE_INITIAL) return _T("Waiting");
		if (eState == E_EXEC_STATE_FINISHED) return _T("Finished");
		if (eState == E_EXEC_STATE_STOPPED) return _T("Stopped");
		if (eState == E_EXEC_STATE_DELAYED) return _T("Delayed");
		if (eState == E_EXEC_STATE_REFRESH) return _T("Postponed");
		if (eState == E_EXEC_STATE_ACTION) return _T("Action forever");
		return _T("???");
	};

protected:
	Tasks*			m_pts;			// only used to display task description
	CImageList		m_imglst;		// task list state img list
	CBitmap			m_bmp;			// helper for m_imglst to store 24bit(true color) bitmap, because CImageList can't do it itself.

	//vector<CStringW>		m_vecTasksInfo;
	vector<CString>			m_vecTasksInfo;
	vector<int>				m_vecToolTipID;
	CToolTipCtrl			m_tt;			// display current pointing task's description tip.

	bool			m_bInited;		// flag of whether view initialized

public:
	virtual BOOL PreCreateWindow(CREATESTRUCT& cs);
	//afx_msg BOOL OnEraseBkgnd(CDC* pDC);
	virtual void OnInitialUpdate();
	afx_msg void OnMouseMove(UINT nFlags, CPoint point);
//	afx_msg void OnRButtonUp(UINT nFlags, CPoint point);
	afx_msg void OnLButtonUp(UINT nFlags, CPoint point);
	virtual BOOL PreTranslateMessage(MSG* pMsg);
};


